<!--
 * @Description: 
 * @Date: 2024-01-26 14:53:41
 * @LastEditTime: 2024-02-02 10:34:30
-->
<template>
  <div class="undertakeSuggest">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="80px"
      v-if="showSearch"
    >
      <el-form-item label="题目" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入题目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          @change="replacePerChange($event)"
        >
          <el-option
            v-for="dict in dict.type.sys_suggest_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="领衔代表" prop="leaderUser">
        <el-input
          v-model="queryParams.leaderUser"
          placeholder="请输入题目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代表团" prop="deId">
        <el-select
          v-model="queryParams.deId"
          placeholder="请选择状态"
          @change="replacePerChange($event)"
        >
          <el-option
            v-for="dict in delegationList"
            :key="dict.deId"
            :label="dict.name"
            :value="dict.deId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-model="loading" border :data="suggestList" style="width: 100%">
      <!-- <el-table-column prop="suggestInfo.suId" label="建议号" align="center"> -->
      <!-- </el-table-column> -->
      <el-table-column prop="suggestInfo.title" label="题目" align="center">
      </el-table-column>

      <el-table-column prop="address" label="代表团" align="center">
        <template slot-scope="scope">
          {{
            scope.row.suggestInfo.leaderUser.deId | delegation(delegationList)
          }}
        </template>
      </el-table-column>
      <el-table-column label="领衔代表" align="center">
        <template slot-scope="scope">
          {{ scope.row.suggestInfo.leaderUser.userName }}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="承办单位" align="center">
        <template slot-scope="scope">
          {{ scope.row.deptId | depName(userList) }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_suggest_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSkip(scope.row)"
            v-hasPermi="['suggest:undertakeSuggest:info']"
            >查看详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleqianBian(scope.row)"
            v-hasPermi="['suggest:undertakeSuggest:qianbian']"
            v-show="scope.row.status == 2"
            >签收或变更</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleReply(scope.row)"
            v-hasPermi="['suggest:undertakeSuggest:reply']"
            v-show="scope.row.status == 4"
            >复函</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEvaluate(scope.row)"
            v-hasPermi="['suggest:undertakeSuggest:evaluate']"
            v-show="scope.row.status == 5"
            >满意度评价</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <replyDialog
      v-if="replyVisible"
      v-model="replyVisible"
      :proId="proId"
      :ruleList="ruleList"
    ></replyDialog>
    <evaluateDialog
      v-if="evaluateVisible"
      v-model="evaluateVisible"
      :proId="proId"
    ></evaluateDialog>
  </div>
</template>

<script>
import { UndertakeInfoList } from "@/api/stage/index.js";
import { getProcessInfoList, userListByRoleId } from "@/api/suggest/index";
import { addDelegationList } from "@/api/dbxx/dbxxgroup/index";
import replyDialog from "./replyDialog.vue";
import evaluateDialog from "./evaluateDialog.vue";
import { mapGetters } from "vuex";
export default {
  name: "undertakeSuggest",
  dicts: ["sys_suggest_status"],
  components: {
    replyDialog,
    evaluateDialog,
  },
  computed: {
    ...mapGetters(["userId", "roles"]),
  },
  data() {
    return {
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        seId: undefined,
        title: undefined,
        submitStatus: undefined,
        leaderId: undefined,
        deId: undefined,
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      sessionList: [],
      delegationList: [],
      suggestList: [],
      userList: [],
      ruleList: [],
      replyVisible: false,
      evaluateVisible: false,
      proId: null,
    };
  },
  filters: {
    delegation(value, delegationList) {
      return delegationList.filter((item) => item?.deId == value)[0]?.name;
    },
    depName(value, userList) {
      let arr = userList.filter((item) => item?.userId == value);
      return arr?.length ? arr[0]?.userName : "暂无";
    },
  },
  created() {
    addDelegationList().then((response) => {
      this.delegationList = response.rows;
    });
    userListByRoleId("9").then((res) => {
      this.userList = res.data.users;
    });
    this.getList();
  },
  methods: {
    /**
     * @description: 详情功能
     * @param {*} row
     * @return {*}
     */
    handleSkip(row) {
      this.$router.push({
        path: "/suggest/suggestInfo",
        query: {
          proId: row.proId,
          type: "readOnly",
        },
      });
    },
    /**
     * @description: 复函
     * @return {*}
     */
    handleReply(row) {
      UndertakeInfoList({
        pageNum: 1,
        pageSize: 100,
      }).then((res) => {
        this.ruleList = res.rows;
        this.replyVisible = true;
        this.proId = row.proId;
      });
    },
    /**
     * @description:  签收或变更
     * @return {*}
     */
    handleqianBian(row) {
      this.$router.push({
        path: "/suggest/suggestInfo",
        query: {
          proId: row.proId,
          type: "readOnly",
          operation: "qianBian",
        },
      });
    },
    /**
     * @description:  满意度评价
     * @return {*}
     */
    handleEvaluate(row) {
      this.evaluateVisible = true;
      this.proId = row.proId;
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    replacePerChange(val) {
      this.$forceUpdate();
    },
    getList() {
      this.loading = true;
      getProcessInfoList({
        ...this.queryParams,
        proStatus: [2, 3, 4, 5, 6],
        deptId: this.userId,
      }).then((res) => {
        this.suggestList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.undertakeSuggest {
  padding: 20px;
}
</style>
